<?php

declare(strict_types=1);

namespace App\CustHub\Model;

use Hyperf\Database\Model\Relations\BelongsToMany;
use Hyperf\Database\Model\Relations\HasMany;
use Mine\MineModel;

/**
 * @property int $id 
 * @property int $uid 
 * @property int $main_uid 
 * @property string $name 规则名称
 * @property int $corp_id 企业ID
 * @property int $trigger_obj 触发对象：0=私聊仅客户触发 1=私聊双方都触发
 * @property int $trigger_type 触发类型：0=模糊关键词 1=精确关键词
 * @property int $match_type 匹配类型：0=满足所有 1=满足任意一个
 * @property \Carbon\Carbon $created_at 创建时间
 * @property \Carbon\Carbon $updated_at 更新时间
 */
class ChKeywordTagScheme extends MineModel
{
    /**
     * The table associated with the model.
     */
    protected ?string $table = 'ch_keyword_tag_scheme';

    /**
     * The attributes that are mass assignable.
     */
    protected array $fillable = ['id', 'uid', 'main_uid', 'name', 'corp_id', 'trigger_obj', 'trigger_type', 'match_type', 'created_at', 'updated_at'];

    /**
     * The attributes that should be cast to native types.
     */
    protected array $casts = ['id' => 'integer', 'uid' => 'integer', 'main_uid' => 'integer', 'corp_id' => 'integer', 'trigger_obj' => 'integer', 'trigger_type' => 'integer', 'match_type' => 'integer', 'created_at' => 'datetime', 'updated_at' => 'datetime'];

    public function keywords(): HasMany
    {
        return $this->hasMany(ChKeywordTagSchemeKeyword::class,'scheme_id','id');
    }

    public function corpTags(): BelongsToMany
    {
        return $this->belongsToMany(ChCorpTag::class,'ch_keyword_tag_scheme_corp_tag','scheme_id','corp_tag_id');
    }

    public function smartTags(): BelongsToMany
    {
        return $this->belongsToMany(ChSmartTag::class,'ch_keyword_tag_scheme_smart_tag','scheme_id','smart_tag_id');
    }
}
